package launcher;

import static java.lang.System.in;
import static java.lang.System.out;

import java.io.File;
import java.util.List;
import java.util.Scanner;

import prober.Category;
import prober.Classifier;
import prober.ContentSummary;
import prober.ContentSummaryBuilder;
import prober.ContentSummaryWriter;
import queries.YahooQueryExecutor;

/**
 * Main command-line interface for QProber System
 *
 *  @author Antonio ak2765
 *  @author Vika vk2185
 */
public class CommandLine {
	
	static {
		System.setProperty("java.util.logging.config.file", "logging.properties");
	}
	
	static boolean DEBUG = false;

	static final Scanner scanner = new Scanner(in);
	
	/**
	 * Here is where the magic begins ...
	 * 
	 * @param args The command line arguments
	 */
	public static void main(String[] args) {
		out.println("COMS E6111 Advanced Database Systems - Professor Gravano - Project2");
		out.println("Students: Antonio Kantek (ak2765) and Vika K. (vk2185)");
		
		out.println("Database (URL, e.g. database.com): ");
		String url = scanner.nextLine();
		
		out.println("Specificity (from 0 to 1): ");
		double specificity = scanner.nextDouble();
		
		out.println("Coverage (1 or more): ");
		int coverage = scanner.nextInt();
		
		out.println("Working...");
		
		Classifier classifier = new Classifier(new YahooQueryExecutor());
		
		List<Category> categories = classifier.QProbe(url, specificity, coverage);

		for(Category category : categories){
		
			ContentSummary contentSummary = new ContentSummaryBuilder().build(category);

			if(!category.isLeaf()){
				File outputFile = new File(category.getCategoryName() + "-" + url + ".txt");
				new ContentSummaryWriter().write(contentSummary, outputFile);
			}
		}	
		
		out.println("Database categories:");
		out.print("\t");
		for(Category category : categories){
			out.print(category.getCategoryName() + "/");
		}
		
	    out.println("\nGood-bye!");
	}

}
